﻿/* 
 *   Copyright (c) Microsoft Corporation.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Microsoft Corporation nor the names of its contributors 
 *       may be used to endorse or promote products derived from this software
 *       without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

using System;

namespace Ogdi.InteractiveSdk.Mvc.Models
{
    [Serializable]
    public class EntitySet : IComparable
    {
        #region Private Members

        // Private member for EntitySet.EntityId
        private Guid entityId;

        // Private member for EntitySet.Name
        private string name;

        // Private member for EntitySet.CategoryValue
        private string categoryValue;

        // Private member for EntitySet.Description
        private string description;

        // Private member for EntitySet.Source
        private string source;

        // Private member for EntitySet.LastUpdateDate
        private DateTime lastUpdateDate;

        // Private member for EntitySet.MetadataUrl
        private System.Uri metadataUrl;

        // Private member for EntitySet.EntitySetName
        private string entitySetName;

        // Private member for EntitySet.EntityKind
        private string entityKind;

        // Private member for EntitySet.ContainerAlias
        private string containerAlias;

        #endregion

        #region Properties

        /// <summary>
        /// This property represents EntityId of the EntitySet.
        /// This property is uniques for each EntitySet
        /// </summary>
        public Guid EntityId
        {
            get { return entityId; }
            set { entityId = value; }
        }       

        /// <summary>
        /// This property represents Name of the EntitySet.
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// This property represents CategoryValue of the EntitySet.
        /// </summary>
        public string CategoryValue
        {
            get { return categoryValue; }
            set { categoryValue = value; }
        }

        /// <summary>
        /// This property represents Description of the EntitySet.
        /// </summary>
        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        /// <summary>
        /// This property represents Source of the EntitySet.
        /// </summary>
        public string Source
        {
            get { return source; }
            set { source = value; }
        }

        /// <summary>
        /// This property represents LastUpdateDate of the EntitySet.
        /// </summary>
        public DateTime LastUpdateDate
        {
            get { return lastUpdateDate; }
            set { lastUpdateDate = value; }
        }

        /// <summary>
        /// This property represents MetadataUrl of the EntitySet.
        /// </summary>
        public Uri MetadataUrl
        {
            get { return metadataUrl; }
            set { metadataUrl = value; }
        }

        /// <summary>
        /// This property represents EntitySetName of the EntitySet.
        /// </summary>
        public string EntitySetName
        {
            get { return entitySetName; }
            set { entitySetName = value; }
        }

        /// <summary>
        /// This property represents EntityKind of the EntitySet.
        /// </summary>
        public string EntityKind
        {
            get { return entityKind; }
            set { entityKind = value; }
        }

        /// <summary>
        /// This property represents Parent of the EntitySet.
        /// </summary>
        public string ContainerAlias
        {
            get { return containerAlias; }
            set { containerAlias = value; }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Default Constructor
        /// </summary>
        public EntitySet()
        {
            //this.EntityId = Guid.Empty;
            this.Name = string.Empty;
            this.CategoryValue = string.Empty;
            this.Description = string.Empty;
            this.Source = string.Empty;
            //this.LastUpdateDate = DateTime.MinValue;
            this.MetadataUrl = new Uri(string.Empty);
            this.EntitySetName = string.Empty;
            //this.EntityKind = string.Empty;
            this.ContainerAlias = string.Empty;          
        }

        /// <summary>
        /// Paramaterized Constructor
        /// </summary>
        /// <param name="entityId">entityId of the EntitySet</param>
        /// <param name="name">name of the EntitySet</param>
        /// <param name="categoryValue">categoryValue of the 
        /// EntitySet</param>
        /// <param name="description">description of the
        /// EntitySet</param>
        /// <param name="source">source of the EntitySet</param>
        /// <param name="lastUpdateDate">lastUpdateDate of 
        /// the EntitySet</param>
        /// <param name="metadataUri">metadataUri of the
        /// EntitySet</param>
        /// <param name="entitySetName">entitySetName of 
        /// the EntitySet</param>
        /// <param name="entityKind">entityKind of the 
        /// EntitySet</param>
        /// <param name="containerAlias">containerAlias of 
        /// the EntitySet</param>        
        public EntitySet(string name, string categoryValue,
            string description, string source,
            Uri  metadataUri, string entitySetName,
            string containerAlias)
        {
            //this.EntityId = entityId;
            this.Name = name;
            this.CategoryValue = categoryValue;
            this.Description = description;
            this.Source = source;
            //this.LastUpdateDate = lastUpdateDate;
            this.MetadataUrl = metadataUri;
            this.EntitySetName = entitySetName;
            //this.EntityKind = entityKind;
            this.ContainerAlias = containerAlias;
        }

        #endregion

        #region IComparable Members

        /// <summary>
        /// This method is overridden for Sort() method
        /// </summary>
        /// <param name="obj">instance of object class</param>
        /// <returns>integer result of comparison</returns>
        public int CompareTo(object obj)
        {
            try
            {
                EntitySet c = obj as EntitySet;

                //return this.Name.CompareTo(c.Name);
                //Fxcop: 
                return string.Compare(this.Name, c.Name, 
                    StringComparison.Ordinal);
            }
            catch (ArgumentException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// overriden the method Equals to match the object of type EntitySet
        /// </summary>
        /// <param name="obj">param of type object</param>
        /// <returns>returns result of match in boolean</returns>
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        /// <summary>
        /// overriden the method GetHashCode
        /// </summary>
        /// <returns>return hashcode</returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// This method overrides == operator
        /// </summary>
        /// <param name="es1">first EntitySey for
        /// comparison</param>
        /// <param name="es2">second EntitySey for 
        /// comparison</param>
        /// <returns>returns true if both passed 
        /// containers are same else false</returns>
        public static bool operator ==(EntitySet es1, EntitySet es2)
        {
            // returns true if both passed containers 
            // are same else false
            return es1.Equals(es2);
        }

        /// <summary>
        /// This method overrides != operator
        /// </summary>
        /// <param name="es1">first EntitySey for
        /// comparison</param>
        /// <param name="es2">second EntitySey for 
        /// comparison</param>
        /// <returns>returns true if first container 
        /// != second container else false</returns>
        public static bool operator !=(EntitySet es1, EntitySet es2)
        {
            // returns true if first container != second 
            // container else false
            return !(es1 == es2);
        }

        /// <summary>
        /// This method overrides less than operator
        /// </summary>
        /// <param name="es1">first EntitySey for 
        /// comparison</param>
        /// <param name="es2">second EntitySey for 
        /// comparison</param>
        /// <returns>returns true if first container 
        /// is less than second container else false</returns>
        public static bool operator <(EntitySet es1, EntitySet es2)
        {
            // returns true if first container is less than 
            // second container else false
            return (es1.CompareTo(es2) < 0);
        }

        /// <summary>
        /// This method overrides greater than operator
        /// </summary>
        /// <param name="es1">first EntitySey for
        /// comparison</param>
        /// <param name="es2">second EntitySey for 
        /// comparison</param>
        /// <returns>returns true if first container is 
        /// greter than second container else false</returns>
        public static bool operator >(EntitySet es1, EntitySet es2)
        {
            // returns true if first container is greter than
            // second container else false
            return (es1.CompareTo(es2) > 0);
        }  
        #endregion
    }
}